<?php require_once 'header.php'; ?>

<div class="content col-md-9" >
 
<?php if(isset($error)):?>
				<p class="error"><?php echo $error?></p>
			<?php endif;?>	
			<?php if(isset($success)):?>
				<p class="success"><?php echo $success?></p>
			<?php endif;?>
    <div class="col-md-6" id="show">
       
			
						<?php if($topics):?>
        <ul id="list-all" class="connected list ui-sortable">
						<?php foreach($topics as $valueshow):?>
                                                    
              
                <li id="listItem_<?php echo $valueshow->topic_news_id; ?>" value="<?php echo $valueshow->topic_news_id; ?>"><img  src="<?php echo base_url("application/views/default/styles/css/img") ?>/arrow.png" alt="move" width="16" height="16" class="handle" /><strong><?php echo $valueshow->topic_news_title; ?></strong></li>
             
            
						<?php endforeach;?>
                </ul>
						<?php endif;?>
						<?php if(!$topics):?>
							<center>Không tìm thấy dữ liệu</center>
						<?php endif;?>
				</div>
<script type="text/javascript">
    function filter() {
        var url = '<?php echo site_url('qltintuc/viewall') ?>' + '/<?php echo "$sort/$order/"; ?>' ;

        var name = $('input[name=name]').val();
        name = (name=='')?0:name;
        url += encodeURIComponent(name) + '/';
        
        var category = $('select[name=category]').val();
        category = (category=='')?0:category;
        url += encodeURIComponent(category) + '/';

        var sub_category = $('select[name=sub_category]').val();
        sub_category = (sub_category=='')?0:sub_category;
        url += encodeURIComponent(sub_category) + '/';
        
        var status = $('select[name=status]').val();
        url += encodeURIComponent(status) + '/';
        
        var limit = $('select[name=limit]').val();
        url += encodeURIComponent(limit) + '/';
        //alert(url);
        window.location.href = url;
    }  
</script>
    <div class="col-md-6">
        <div class="row">

            <ul id="test-list" class="connected list no2">
                <?php foreach ($topic as $value){ ?>
                <li id="listItem_<?php echo $value->topic_news_id; ?>" value="<?php echo $value->topic_news_id; ?>"><img  src="<?php echo base_url("application/views/default/styles/css/img") ?>/arrow.png" alt="move" width="16" height="16" class="handle" /><strong><?php echo $value->topic_news_title; ?></strong><a  id="xoalist" href="<?php echo base_url(); ?>qltintuc/xoanumber/<?php echo $value->topic_news_id; ?>">Xóa</a></li>
             
                <?php } ?>
            </ul>

        </div>
    </div>
</div><!-- content-->
 Total topic <?php echo $totaltopic; ?>
		                    <?php echo $this->pagination->create_links() ?>
<div class="grid_4">
		        <p>
		            <label>Name</label>
		            <input type="text" name="name" id="name" value="<?php if (isset($name) && $name) echo $name; ?>" />
		        </p>
		    </div> 
		    <div class="grid_4">
		        <p>
		            <label>Category</label>
		            <select name="category">
		                <option value="0">All</option>
		                <?php foreach ($categorys as $category): ?>
                            <option value="<?= $category->category_id ?>" <?php if ($category_filter == $category->category_id) echo "selected='selected'"; ?>>
                            <?= $category->category_name ?>
                            </option>
                    	<?php endforeach; ?>
		            </select>    
		        </p>
		    </div>
		    <div class="grid_4">
		        <p>
		            <label>Sub Category</label>
		            <select name="sub_category">
		                <option value="0">All</option>
		                <?php foreach ($sub_categorys as $sub_category): ?>
                            <option value="<?= $sub_category->sub_category_id ?>" <?php if ($sub_category_filter == $sub_category->sub_category_id) echo "selected='selected'"; ?>>
                            <?php echo $sub_category->sub_category_name ?>
                            </option>
                    	<?php endforeach; ?>
		            </select>    
		        </p>
		    </div>
		   <div class="grid_4">
		        <p>
		            <label>Publish</label>
		            <select name="status">
		                <option value="-1" selected='selected'>All</option>
		                <option value="1" <?php if($status==1) echo "selected='selected'"?>>Bật</option>
		                <option value="0" <?php if($status==0) echo "selected='selected'"?>>Tắt</option>
		            </select>
		        </p>
		    </div>
		    <div class="grid_4">
		        <p>
		            <label>Limit</label>
		            <select name="limit">
		                <option value="10" <?php if ($limit == 10) echo 'selected="selected"'; ?>>10</option>
		                <option value="25" <?php if ($limit == 25) echo 'selected="selected"'; ?>>25</option>
		                <option value="50" <?php if ($limit == 50) echo 'selected="selected"'; ?>>50</option>
		                <option value="100" <?php if ($limit == 100) echo 'selected="selected"'; ?>>100</option>
		                <option value="500" <?php if ($limit == 500) echo 'selected="selected"'; ?>>500</option>
		            </select>
		        </p>
		    </div>    
		    <div class="grid_2">
		        <p>
		            <label>Lọc</label>
		            <input type="button" onclick="filter();" value="Filter" />
		        </p>
		    </div>
 <script type="text/javascript">
    // When the document is ready set up our sortable with it's inherant function(s)
    $(document).ready(function() {
        $('#test-list').sortable({
            connectWith: '.list',
            update: function() {
                var ketqua = new Array();
                
                var order = $('#test-list').sortable('toArray', {attribute: 'value'});
                
            $.each(order,function(key,value){
               ketqua[key] = value; 
            });
           var data = {
               "ketqua[]" : ketqua
           }
           console.log(data);
           $.post("<?php echo base_url(); ?>qltintuc/suanumber",data,function(data2,status){
              console.log(data2);
             });

               
                
            }
        });
        
               $('.connected').sortable({
            connectWith: '.connected',
        });
        
    });
</script>
<?php require_once 'footer.php'; ?>